package com.jindy.module.goodscollection.service.impl;

import java.util.List;

import com.jindy.common.core.domain.entity.SysUser;
import com.jindy.common.utils.DateUtils;
import com.jindy.common.utils.SecurityUtils;
import com.jindy.module.goodscollection.domain.GoodsCollection;
import com.jindy.module.goodscollection.mapper.GoodsCollectionMapper;
import com.jindy.module.goodscollection.service.IGoodsCollectionService;
import com.jindy.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 物品领用Service业务层处理
 *
 * @author ruoyi
 * @date 2022-09-18
 */
@Service
public class GoodsCollectionServiceImpl implements IGoodsCollectionService
{
    @Autowired
    private GoodsCollectionMapper goodsCollectionMapper;
    @Autowired
    private ISysUserService sysUserService;
    /**
     * 查询物品领用
     *
     * @param id 物品领用主键
     * @return 物品领用
     */
    @Override
    public GoodsCollection selectGoodsCollectionById(Long id)
    {
        return goodsCollectionMapper.selectGoodsCollectionById(id);
    }

    /**
     * 查询物品领用列表
     *
     * @param goodsCollection 物品领用
     * @return 物品领用
     */
    @Override
    public List<GoodsCollection> selectGoodsCollectionList(GoodsCollection goodsCollection)
    {
        return goodsCollectionMapper.selectGoodsCollectionList(goodsCollection);
    }

    /**
     * 新增物品领用
     *
     * @param goodsCollection 物品领用
     * @return 结果
     */
    @Override
    public int insertGoodsCollection(GoodsCollection goodsCollection)
    {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        goodsCollection.setCreateBy(sysUser.getUserName());
        goodsCollection.setUserId(sysUser.getUserId());
        goodsCollection.setUserName(sysUser.getUserName());
        goodsCollection.setDeptId(sysUser.getDeptId());
        goodsCollection.setDeptName(sysUser.getDept().getDeptName());
        goodsCollection.setCreateTime(DateUtils.getNowDate());
        return goodsCollectionMapper.insertGoodsCollection(goodsCollection);
    }

    /**
     * 修改物品领用
     *
     * @param goodsCollection 物品领用
     * @return 结果
     */
    @Override
    public int updateGoodsCollection(GoodsCollection goodsCollection)
    {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        goodsCollection.setUpdateBy(sysUser.getUserName());
        goodsCollection.setUpdateTime(DateUtils.getNowDate());
        return goodsCollectionMapper.updateGoodsCollection(goodsCollection);
    }

    /**
     * 批量删除物品领用
     *
     * @param ids 需要删除的物品领用主键
     * @return 结果
     */
    @Override
    public int deleteGoodsCollectionByIds(Long[] ids)
    {
        return goodsCollectionMapper.deleteGoodsCollectionByIds(ids);
    }

    /**
     * 删除物品领用信息
     *
     * @param id 物品领用主键
     * @return 结果
     */
    @Override
    public int deleteGoodsCollectionById(Long id)
    {
        return goodsCollectionMapper.deleteGoodsCollectionById(id);
    }
}
